/*
    photoresistor led
    
    circuit - 
    10K resistor between 5V and A0.  
    Photoresistor between A0 and ground.
    D3 -> 220 resistor -> LED -> ground
 */


// these values are set by loading the example sketch under 
// "File/Examples/Basics/AnalogReadSerial", opening the serial
// console, then covering and uncovering the photoresistor.
// note the approximate largest and smallest values, and put them in
// these two #defines.

#define min_reading 280
#define max_reading 640

void setup() {
}

void loop() {
  int sensorValue = analogRead(A0);
  
  // constrain makes sure that if we are bit low or high, we aren't out
  // of range.  The map just does a linear map to 0-255
  int brightness = map(constrain(sensorValue,min_reading,max_reading),
          min_reading, max_reading, 0, 255);
  
  analogWrite(3, brightness);
  
  // analogWrite puts out a PWM signal at around 500Hz.  This makes sure we
  // get at least several cycles of the signal before changing it again.
  // Will work without this, need to check to see how much difference it makes
  delay(5);
}
